package com.xuecheng.filesystem.controller;

import com.xuecheng.api.filesystem.FileSystemControllerApi;
import com.xuecheng.filesystem.service.FileSystemService;
import com.xuecheng.filesystem.service.UploadService;
import com.xuecheng.framework.domain.filesystem.response.UploadFileResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ShengJinFeng
 * @version V1.0
 * @ClassName FileSystemController
 * @Description (这里用一句话描述这个类的作用)
 * @date 2020/2/7 18:21
 * @since V1.0
 */
@RestController
@RequestMapping("/filesystem")
@Api(value="文件系统接口",description = "件系统接口，提供文件的上传和下载")
public class FileSystemController implements FileSystemControllerApi {

    @Autowired
    private FileSystemService fileSystemService;

    @Autowired
    private UploadService uploadService;

    @Override
    @ApiOperation("上传文件")
    @PostMapping("upload")
    public UploadFileResult upload(@RequestParam("file") MultipartFile file,
                                   @RequestParam(value = "filetag",required = true) String filetag,
                                   @RequestParam(value = "businesskey",required = false) String businesskey,
                                   @RequestParam(value = "metadata",required = false) String metadata) {
        //return fileSystemService.upload(file,filetag,businesskey,metadata);
        return uploadService.upload(file,filetag,businesskey,metadata);
    }

    /*@ApiOperation("上传图片")
    @PostMapping("image")
    public String uploadImage(@RequestParam("file")MultipartFile file){
        String url = uploadService.uploadImage((file));
        return url;
    }*/
}
